const {
  default: Toast
} = require("../../../vant/weapp/toast/toast");
import clickreply from "../../../utils/clickreply.js";

// pages/person/vip/index.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    store: [],
    index: 0,
    vipList: [],
    isVipList: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this
    app.http.post(app.api.store, {}, (res) => {
      console.log(res)
      that.setData({
        store: res.data
      })
      that.getVipList()
    })
  },
  // 购买会员
  buyVip(e) {
    if (clickreply.preventDuplicateClicks(6)) return;
    const that = this
    let store_id = that.data.store[that.data.index].store_id.toString()
    let level_id = e.currentTarget.dataset.id.toString()

    app.http.post(app.api.addLevel, {
      store_id,
      level_id
    }, (res) => {
      console.log(res.data.order_on)
      app.http.wecat(res.data.order_on, 2, (res) => {
        console.log(11, res)
      })
    })
  },
  // 会员列表
  getVipList() {
    const that = this

    let store_id = that.data.store[that.data.index].store_id.toString()
    app.http.post(app.api.Recharge, {
      store_id
    }, (res) => {
      if (res.data == "") {
        that.setData({
          vipList: res.data,
          isVipList: true
        })
      } else {
        that.setData({
          vipList: res.data,
          isVipList: false
        })
      }

    })
  },
  bindPickerChange(e) {
    this.setData({
      index: e.detail.value
    })
    this.getVipList()
  },

});